package com.ruoyi.web.controller.community.owner;

import java.util.List;

import com.ruoyi.community.domain.BaseNotice;
import com.ruoyi.community.service.IBaseNoticeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.OwnerNotice;
import com.ruoyi.community.service.IOwnerNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 信息公告Controller
 * 
 * @author ruoyi
 * @date 2021-09-26
 */
@RestController
@RequestMapping("/community/owner/notice")
public class OwnerNoticeController extends BaseController
{
    @Autowired
    private IOwnerNoticeService ownerNoticeService;

    @Autowired
    private IBaseNoticeService baseNoticeService;

    /**
     * 查询信息公告列表
     */
//    @PreAuthorize("@ss.hasPermi('community:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnerNotice ownerNotice)
    {
        startPage();
        List<OwnerNotice> list = ownerNoticeService.selectOwnerNoticeList(ownerNotice);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('community:notice:list')")
    @GetMapping("/preview")
    public TableDataInfo preview(BaseNotice baseNotice)
    {
        startPage();
        baseNotice.setSectionId("2");
        List<BaseNotice> list = baseNoticeService.selectBaseNoticePreviewWithoutPic(baseNotice);
//        for (int i = 0; i < list.size(); i++) {
//            list.get(i).setContent(null);
//        }
        return getDataTable(list);
    }

//    /**
//     * 导出信息公告列表
//     */
////    @PreAuthorize("@ss.hasPermi('community:notice:export')")
//    @Log(title = "信息公告", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(OwnerNotice ownerNotice)
//    {
//        List<OwnerNotice> list = ownerNoticeService.selectOwnerNoticeList(ownerNotice);
//        ExcelUtil<OwnerNotice> util = new ExcelUtil<OwnerNotice>(OwnerNotice.class);
//        return util.exportExcel(list, "信息公告数据");
//    }

    /**
     * 获取信息公告详细信息
     */
//    @PreAuthorize("@ss.hasPermi('community:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") String noticeId)
    {
        return AjaxResult.success(baseNoticeService.selectBaseNoticeById(noticeId));
    }

    /**
     * 新增信息公告
     */
//    @PreAuthorize("@ss.hasPermi('community:notice:add')")
    @Log(title = "业委会公告", businessType = BusinessType.INSERT)
    @PostMapping
//    public AjaxResult add(@RequestBody OwnerNotice ownerNotice)
    public AjaxResult add(@RequestBody BaseNotice baseNotice)
    {
        baseNotice.setSectionId("2");
        return toAjax(baseNoticeService.insertBaseNotice(baseNotice));
    }

    /**
     * 修改信息公告
     */
//    @PreAuthorize("@ss.hasPermi('community:notice:edit')")
    @Log(title = "信息公告", businessType = BusinessType.UPDATE)
    @PutMapping
//    public AjaxResult edit(@RequestBody OwnerNotice ownerNotice)
    public AjaxResult edit(@RequestBody BaseNotice baseNotice)
    {
        return toAjax(baseNoticeService.updateBaseNotice(baseNotice));
    }

    /**
     * 删除信息公告
     */
//    @PreAuthorize("@ss.hasPermi('community:notice:remove')")
    @Log(title = "信息公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable String[] noticeIds)
    {
        return toAjax(baseNoticeService.deleteBaseNoticeByIds(noticeIds));
    }
}
